<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    use HasFactory;

    protected $fillable = ['title','address','logo','uscc','mobile','contacts','scale','thali','expire','status'];

    const POSTONLY = ['title','address','logo','uscc','mobile','contacts','scale','thali','expire','status'];

    protected $appends = [
        'status_text'
    ];

    protected $casts = [
        'status' => 'boolean',
    ];

    public function getStatusTextAttribute()
    {
        return $this->status ? '启用' : '禁用';
    }
    
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function projects()
    {
        return $this->hasMany(Project::class)->select('id','title');
    }
}
